import API, { ENV } from './endpoints'

/**
 * 根据服务名称和服务参数返回请求的url和options
 */
export default ({ serviceName = '', serviceArguments = {} }) => {
  const { method, endpoint } = API[serviceName]
  const urlBase = `${ENV}${endpoint}`
  const { queryString, headers } = getQueryStringAndHeaders(serviceArguments)

  let url, body, options
  if (method === 'POST') {
    url = urlBase
    body = queryString
    options = { headers, method, body }
  }
  
  if (method === 'GET') {
    url = `${urlBase}?${queryString}`
    options = { headers, method }
  }

  return {
    url,
    options,
  }
}

/**
 * getQueryStringAndHeaders() 及其他Helpers(略)
 */